package com.haiertvbic.tvnow.protocol;

public class ConnectManager {
	
	public static String LOCAL_HOST = "127.0.0.1";
	
	public static final byte[] intToByte(int i) {
        byte[] abyte0 = new byte[4];
        abyte0[3] = (byte) (0xff & i);
        abyte0[2] = (byte) ((0xff00 & i) >> 8);
        abyte0[1] = (byte) ((0xff0000 & i) >> 16);
        abyte0[0] = (byte) ((0xff000000 & i) >> 24);
        return abyte0;
    }
	
	public static final int bytesToInt(byte[] bytes) {
	        int addr = bytes[0] & 0xFF;
	        addr |= ((bytes[1] << 8) & 0xFF00);
	        addr |= ((bytes[2] << 16) & 0xFF0000);
	        addr |= ((bytes[3] << 24) & 0xFF000000);
	        return addr;
	    }
	  
	  /**
	   * 将字符型转换为字节数组型
	   */
	public static byte[] charToByte(char timeType) {
		// TODO Auto-generated method stub
		byte[] tempByte = String.valueOf(timeType).getBytes();
		return tempByte;
		}
	  
	  /** 
	     * short到字节数组的转换
	     * 
	     * @param s 
	     * @return 
	     */ 
    public static byte[] shortToByte(short number) { 
        int temp = number; 
        byte[] b = new byte[2]; 
        for (int i = b.length - 1; i >= 0; i--) { 
            b[i] = new Integer(temp & 0xff).byteValue();//将最低位保存在最低位 
            temp = temp >> 8; // 向右移8位 
        } 
        return b; 
    } 

    public static short bytesToShort(byte[] bytesShort) {
    	short sRet = 0;
    	sRet += (bytesShort[0] & 0xFF) << 8;
    	sRet += bytesShort[1] & 0xFF;
    	return sRet;
    	}
}
